/* Copyright 2011 Elektrobit Wireless Communications Oy (EB)


  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 2 as 
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


 *All rights reserved 
 *Version:Elektrobit_Qt_1.0.0_20110305 */


import Qt 4.7

Item {
    property int itemWidth: 100
    property int itemHeight: itemWidth

    property int currentIndex: 0
    property bool moving: aa.moving

   // signal itemSelected(int index)
    signal currentItemClicked(int index)



    id:rect
    width: 640; height: 200

    ListModel {
        id: mylist
        ListElement {
            icon: "../../images/sys/menu_btn_movie_select.png"
            name: "Moive"
        }
        ListElement {
            icon: "../../images/sys/menu_btn_music_select.png"
            name: "Music"
        }
        ListElement {
            icon: "../../images/sys/menu_btn_message_select.png"
            name: "Image"
        }
        ListElement {
            icon: "../../images/sys/menu_btn_about_select.png"
            name: "Web"
        }
    }

    Component {
        id: delegate

        Item {
            id:itema
            width: itemWidth
            height: itemHeight

            scale: PathView.scale
            opacity: PathView.opacity

            Rectangle{
                id:ss

                width:parent.width
                height:parent.height
                border.color: "skyblue"
                border.width: 5
                color: Qt.rgba(0,0,0,0.0)

                radius:5
                visible:aa.currentIndex == index&!aa.moving
                opacity: 0.7
            }

            Image {
                anchors.horizontalCenter: ss.horizontalCenter
                anchors.verticalCenter: ss.verticalCenter
                width: parent.width
                height: parent.height
                source: icon
            }

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    if(aa.currentIndex == index){
                        console.log("click");
                        rect.currentItemClicked(aa.currentIndex);
                    }
                    else{
                        aa.currentIndex=index;
                        console.log("click move end");
                        console.log("currentIndex:", aa.currentIndex);
                        rect.currentIndex = aa.currentIndex;
                    }
                }
            }
        }
    }

    PathView {
        id:aa

        anchors.fill: parent
        model: mylist
        delegate: delegate

        clip: false

        path: Path {
            startX: rect.width/2;
            startY: rect.height/2 + itemHeight/3
            PathAttribute{name:"scale";value:1.0}
            PathAttribute{name:"opacity";value:1.0}
            PathQuad { x: rect.width/2; y: rect.height/2 - itemHeight*2/3; controlX: rect.width/2-200; controlY: rect.height/2 + itemHeight*0.3 }
            PathAttribute{name:"scale";value:0.6}
            PathAttribute{name:"opacity";value:0.3}
            PathQuad { x: rect.width/2; y: rect.height/2 + itemHeight/3; controlX: rect.width/2+200; controlY: rect.height/2 - itemHeight*0.3}
        }

        onMovementEnded:{
            console.log("move end");
            console.log("currentIndex:", aa.currentIndex);
            rect.currentIndex = aa.currentIndex;

        }

    }


    onCurrentIndexChanged:{

        console.log("index changed!")

    }
}









